dabaotuMgr = {}
QMPlugin = dabaotuMgr
function dabaotuMgr.init()
    dabaotuMgr.paraConfig = {
        ["任务按钮"] = {974,1336,1077,1435,"CBF0FE","12|-13|C2D5D3,-12|-6|A4D3E3,-33|-6|A7D8E5,-27|-6|ACDBEA,-42|16|98C1D2,-41|-7|94B8C4,3|19|D3F5FF,-23|22|ABD5DC,16|22|E5F5F6",0,0.85},
        ["任务按钮red"] = {984,1342,1078,1431,"D9F5FF","11|-6|EEFBFF,17|27|315DF6,20|19|315DF6,10|28|315DF6,-9|-1|C4EFFF",0,0.85},
        ["宝图任务前往按钮"] = {14,1070,1065,1909,"A1D5F6","34|-389|1A2B73,20|-382|223479,37|-388|C3E4FA,31|-359|97B3D6,32|-354|23357A,36|-327|25377B,-4|-4|1D3076,20|-315|203278,29|-152|C8EAFE",0,0.85},
        ["宝图任务可做"] = {31,1085,1057,1887,"199C63","0|-21|1B9B63,115|-501|213378,95|-493|233579,105|-486|C7EAFE,106|-469|1F3077,109|-469|C4E5FB,99|-461|C8EAFE,105|-435|1E3076,100|-408|1B2D74",0,0.85},
        ["宝图任务领取按钮"] = {27,1036,1073,1915,"199C63","2|-13|269E70,116|-501|1F3072,97|-493|1D2F72,117|-479|1E3075,107|-469|1F3077,98|-477|C1E3F9,99|-453|C7EAFD,106|-435|1E3076,101|-408|1B2D74",0,0.85},
    }
end

-- 判断任务按钮
local function checkTaskBtn()
    local para = dabaotuMgr.paraConfig["任务按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function checkTaskRedBtn()
    local para = dabaotuMgr.paraConfig["任务按钮red"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function checkTaskAvailable()
    local para = dabaotuMgr.paraConfig["宝图任务可做"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
mlog.info("itemX 》》》》》》》》》》》》》》》", itemX)
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

local function checkbaotuTaskGoBtn()
    local para = dabaotuMgr.paraConfig["宝图任务前往按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 判断任务领取按钮
local function checkTaskAcceptBtn()
    local para = dabaotuMgr.paraConfig["宝图任务领取按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 领取宝图任务
local function acceptTask()

    local taskBtnShow,x,y = false,-1,-1
    while not taskBtnShow do
        taskBtnShow,x,y = checkTaskBtn()
        if taskBtnShow then
            mlog.info("发现任务按钮")
            game.tap(x,y)
        else
            taskBtnShow,x,y = checkTaskRedBtn()
            if taskBtnShow then
                mlog.info("发现任务按钮red")
                game.tap(x,y)
            else
                mlog.info("没有发现任务按钮,尝试打开任务按钮")
                game.tap(1034,1582)
            end
        end
        game.delay(1000)
    end
    game.delay(1000)
    local available = checkTaskAvailable()
    if not available then
        return available
    end

    local taskGoBtnShow,x,y = checkbaotuTaskGoBtn()
    if taskGoBtnShow then
        mlog.info("发现任务前往按钮")
        game.tap(x,y)
        game.delay(2000)
        local findAcceptBtnShow,x,y = false, -1,-1
        while not findAcceptBtnShow do
            mlog.info("等待接跑图任务")
            findAcceptBtnShow,x,y = checkTaskAcceptBtn()
            if findAcceptBtnShow then
                mlog.info("发现跑图任务领取按钮")
                game.tap(x,y)
                game.delay(800)
            end
            game.delay(2000)
        end
    end
    game.delay(500)
    return true
end

function dabaotuMgr.execTask()
    LuaAuxLib.TracePrint("开打打宝图 execTask")
    local accept = acceptTask()
    if not accept then
        mlog.info("无宝图任务可做")
        return
    end


end